package com.mapapp.flutter_mapapp.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.mapapp.flutter_mapapp.R;
import com.mapapp.flutter_mapapp.adapter.ErrorCorrectionAdapter;
import com.mapapp.flutter_mapapp.bean.FixBean;
import com.mapapp.flutter_mapapp.persenter.ErrorCorrectionPresenter;
import com.mapapp.flutter_mapapp.view.ErrorCorrectionViewInterface;
import com.mapapp.flutter_mapapp.widget.TitleBar;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MyErrorCorrectionActivity extends ImmersiveBaseActivity implements ErrorCorrectionViewInterface {
    @BindView(R.id.title_bar)
    TitleBar titleBar;
    @BindView(R.id.rv_error_correction)
    RecyclerView rvErrorCorrection;
    private ErrorCorrectionAdapter errorCorrectionAdapter;

    private ErrorCorrectionPresenter presenter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_error_correction);
        ButterKnife.bind(this);
        presenter = new ErrorCorrectionPresenter(this, this, lifecycleSubject);

        errorCorrectionAdapter = new ErrorCorrectionAdapter(R.layout.item_error_correction);
        rvErrorCorrection.setLayoutManager(new LinearLayoutManager(mContext));
        rvErrorCorrection.setAdapter(errorCorrectionAdapter);

        errorCorrectionAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                FixBean fixBean = errorCorrectionAdapter.getData().get(position);
                Intent intent = new Intent(mContext, FixSeparationActivity.class);
                intent.putExtra("auditId", fixBean.getAudit_id());
                intent.putExtra("separation", fixBean.getType() == 1);
                startActivity(intent);
            }
        });

        titleBar.getIvBack().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });


        presenter.fetchFixList();

    }


    @Override
    public void showList(List<FixBean> fixBeanList) {
        errorCorrectionAdapter.setNewData(fixBeanList);
    }
}
